const router = require('koa-router')();
const { models, sequelize } = require('../../utils/db');
const { resBody } = require('../../utils/index')

router.post('/getSpecial', async(ctx) => {
    let ps = 10,
        pn = 1,
        condition = {};
    let data = await models.special_model.findAll({
        raw: true,
        where: condition,
        order: [ 
          [sequelize.literal('RAND()')] 
        ],
        attributes: ['sid', 'title', 'categoryId'],
        limit: ps,
        offset: (pn - 1) * ps
    });
    let count = await models.special_model.count({
        where: condition
    });
    let maxPage = Math.ceil(count / ps)
    ctx.body = {
        ...resBody.success,
        data,
        count,
        maxPage
    };
});

module.exports = router